#ifndef TRIM_STRING_H
#define TRIM_STRING_H

#include <string>
#include <ctype.h>
inline std::string trim(const std::string& s)
{
	int beg = s.length();
	for (unsigned i = 0; i < s.length(); ++i)
	{
		if (!isspace(s[i]))
		{
			beg = i;
			break;
		}
	}
	int end = beg - 1;
	for (int i = s.length() - 1 ; i >= beg; --i)
	{
		if (!isspace(s[i]))
		{
			end = i;
			break;
		}
	}
	if (beg > end)
		return std::string("");
	else
		return s.substr(beg, (end+1) - beg);
}

#endif	//TRIM_STRING_H
